package com.baiyue.controller;


import com.baiyue.entity.ProductCategory;
import com.baiyue.model.SelectOptionsResult;
import com.baiyue.model.productCategory.ProductCategoryDataRequest;
import com.baiyue.model.productCategory.ProductCategoryDataResponse;
import com.baiyue.model.productInfo.ProductInfoDataRequest;
import com.baiyue.result.Result;
import com.baiyue.service.ProductCategoryService;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/api/productCategory")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;

    @PostMapping("/add")
    public Result<Boolean> addProductCategory(@RequestBody ProductCategoryDataRequest request){
        productCategoryService.insert(request);
        return Result.success(true);
    }

    @PostMapping("/getSelect")
    public Result<List<SelectOptionsResult>> getSelectOptions(){
        return Result.success(productCategoryService.getSelectOptions());
    }

    @PostMapping("/update")
    public Result<Boolean> updateProductCategory(@RequestBody ProductCategoryDataRequest request){
        productCategoryService.updateCategory(request);
        return Result.success(true);
    }

    @PostMapping("/delete")
    public Result<Boolean> deleteProductCategory(@RequestBody ProductCategoryDataRequest request){
        return Result.success(productCategoryService.deleteCategoryByIds(request));
    }

    @PostMapping("/list")
    public Result<Page<ProductCategoryDataResponse>> findByPage(@RequestBody ProductCategoryDataRequest request){
        return Result.success(productCategoryService.findByPage(request));
    }
 }

